<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('电子名片商户成员列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <input type="hidden" name="merchantId" th:value="${merchantId}"/>
                            <input type="hidden" name="merchantType" th:value="${merchantType}"/>
                        </li>

                        <!--<li>
                           <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                   class="fa fa-search"></i>&nbsp;搜索</a>
                           <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                   class="fa fa-refresh"></i>&nbsp;重置</a>
                       </li>-->
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="exportExcel()"  >
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('merchant:part:edit')}]];
    var removeFlag = [[${@permission.hasPermi('merchant:part:remove')}]];
    var sexDatas = [[${@dict.getType('cif_sex')}]];
    var statusDatas = [[${@dict.getType('common_yes_no')}]];
    var personalBusiDatas = [[${@dict.getType('ecard_personal_business_tag')}]];
    var agricultureRlationshipDatas = [[${@dict.getType('ecard_agriculture_relationship')}]];
    var merchantPositionDatas = [[${@dict.getType('ecard_merchant_position')}]];
    var enterprisePositionDatas = [[${@dict.getType('ecard_enterprise_position')}]];
    var personalTagDatas = [[${@dict.getType('ecard_personal_tag')}]];
    var prefix = ctx + "merchant/info/part";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "电子名片商户成员",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'handName',
                    title: '门头名称'
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'idCard',
                    title: '身份证号'
                },
                {
                    field: 'duties',
                    title: '职务',
                    formatter: function (value, row, index) {
                        if (row.merchantType == '2'){
                            return $.table.selectDictLabel(merchantPositionDatas, value);
                        } else if (row.merchantType == '3'){
                            return $.table.selectDictLabel(enterprisePositionDatas, value);
                        }

                    }
                },
                {
                    field: 'businessDemand',
                    title: '业务需求',
                    formatter: function (value, row, index) {
                        var array = [];
                        var val='';
                        if(value != null ){
                            array = value.split(",");
                        }
                        for(var i=0;i<array.length;i++){
                            val+=$.table.selectDictLabel(personalBusiDatas, array[i])+' '
                        }
                        return val;
                    }
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sexDatas, value);
                    }
                },
                {
                    field: 'isContacts',
                    title: '是否联系人',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'memberLabel',
                    title: '成员标签',
                    formatter: function (value, row, index) {
                        var array = [];
                        var val='';
                        if(value != null ){
                            array = value.split(",");
                        }
                        for(var i=0;i<array.length;i++){
                            if(i < array.length -1){
                                val+=$.table.selectDictLabel(personalTagDatas, array[i])+','
                            }else{
                                val+=$.table.selectDictLabel(personalTagDatas, array[i])+' '
                            }
                        }
                        return val;
                    }
                },
                {
                    field: 'relationship',
                    title: '关系',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(agricultureRlationshipDatas, value);
                    }
                },
                {
                    field: 'learnWorkSituation',
                    title: '学习或工作情况'
                },
                {
                    field: 'userName',
                    title: '营销经理'
                },
                {
                    field: 'creationTime',
                    title: '创建时间'
                }]
        };
        $.table.init(options);
    });

    function exportExcel(){
        var dataParam = $("#formId").serializeArray();
        var ids = $.table.selectColumns("id");
        var tipMsg = "确定导出所有数据吗？";
        if($.common.isNotEmpty(ids)){
            tipMsg = "确定导出勾选" + ids.length + "条数据吗？";
            dataParam.push({ "name": "ids", "value": ids });
        }
        dataParam = JSON.stringify(dataParam);
        $.modal.confirm(tipMsg, function() {
            window.location.href = prefix + "/export/" + dataParam;
        });
    }
</script>
</body>
</html>